<?php

class Users extends CI_Model {

	//mo3ath
	function validate($username,$password)
	{
		$this->db->where('email', $username);
		$this->db->where('password', md5($password));
		$query = $this->db->get('userprofile');
		
		if($query->num_rows() == 1)
		{
			return true;
		}
		else
			return false;
	}
	//mo3ath
	function create_profile($firstname,$lastname,$email,$password,$dateOfBirth,$registrationDate)
	{
		$new_profile_insert_data = array(
			'firstName' => $firstname,
			'lastName' => $lastname,
			'email' => $email,
			'password' => md5($password),
			'dateOfBirth' => $dateOfBirth,
			'registrationDate' => $registrationDate
		);
		$insert = $this->db->insert('userprofile', $new_profile_insert_data);
		return $insert;
	}
	//mo3ath
	function isRegistered($username)
	{
		$this->db->where('email', $username);
		$query = $this->db->get('userprofile');
		if($query->num_rows > 0)
			return true;

		else
			return false;

	}
        
        function getInformation($email)
        {
            // this is to retreive the information of the user
            
            $this->db->from('userprofile');
            $this->db->where('email',$email);
            $query=$this->db->get();
            return $query; 
        }
        
        function setInformationNoP($email,$data) // when the user doesnt change the password
        {
            
           $this->db->where('email', $email);
		$update= $this->db->update('userprofile',$data ); //the third parameter is for WHERE claus
		return $update;
        }

        function setInformationWP($email,$data) // when the user do change the password
        {
             $this->db->where('email', $email);
		$update= $this->db->update('userprofile',$data ); //the third parameter is for WHERE claus
		return $update;
        }

        function getPassword ($email)
        {
            $this->db->select('password');
            $this->db->from('userprofile');
            $this->db->where('email',$email);
            $query=$this->db->get(); // getting the result "password"

            return $query;

        }

        function notification($sit_id)
        {
            $this->db->select('firendEmail');
            $this->db->from('situationfriendlist');
            $this->db->where('SituationID',$sit_id);
            $query=$this->db->get();
        }
}